package com.yq.ylmall.common.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class RandomUtil {
    // 生成 18位 类型String
    public static String createId() {
        return createLongId().toString();
    }

    // 生成 18位 类型Long
    public static Long createLongId() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String date = sdf.format(new Date());
        StringBuilder stringBuilder = new StringBuilder();
        Random random = new Random();
        stringBuilder.append(date);
        for (int i = 0; i < 4; i++) {
            stringBuilder.append(random.nextInt(10));
        }
        return Long.valueOf(stringBuilder.toString());
    }

    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < 100; i++) {
            System.out.println(createLongId());
        }
    }
}
